package BehavioralPattern.Command.Extend;

import java.util.ArrayList;
import java.util.List;

/**
 * 需求：有个固定命令组合会多次被执行
 * 解决：加入合成模式，实现方法如下，定义一个宏命令类
 * 
 * @author Xinz
 *
 */
public class MarcoCommand implements Command {

	private List<Command> cmdList = new ArrayList();
	
	public void add(Command command) {
		cmdList.add(command);
	}
	
	public void remove(Command command) {
		cmdList.remove(command);
	}
	
	@Override
	public void execute() {
		Command cmd;
		for(int i = 0;i < cmdList.size(); ++i) {
			cmd = cmdList.get(i);
			cmd.execute();
		}
	}

	@Override
	public String getName() {
		return this.getName();
	}

}
